#ifndef __BASIC_FRAMEWORK_EVENT_HANDLE_H__
#define __BASIC_FRAMEWORK_EVENT_HANDLE_H__

#include "library2/libobject.h"
#include "library2/libexception.h"

namespace basic
{
    namespace framework
    {
		class IReactor;
		class IEventHandler: public basic::library2::CObject
		{
		public:

			enum EventMask
			{
				NULL_MASK      = 0x00000000,
				READ_MASK      = 0x00000001,
				WRITE_MASK     = 0x00000002,
				EXCEPT_MASK    = 0x00000004,
				ACCEPT_MASK    = 0x00000008,
				CONNECT_MASK   = 0x00000010,
				TIMER_MASK     = 0x00000020,
				SIGNAL_MASK    = 0x00000040,
				DONT_CALL      = 0x10000000,

				ALL_EVENTS_MASK= READ_MASK   |
								WRITE_MASK   |
								EXCEPT_MASK  |
								ACCEPT_MASK  |
								CONNECT_MASK |
								TIMER_MASK   |
								SIGNAL_MASK
			};
			virtual apr_uint64_t GetHashCode() const = 0;
			virtual std::string ToString() const = 0;

			// The handle_close(NDK_HANDLE, EventMask) will be called if return -1. 
			virtual apr_status_t HandleInput (F_HANDLE *hHandle) = 0;
		    
			// The handle_close(NDK_HANDLE, EventMask) will be called if return -1. 
			virtual apr_status_t HandleOutput (F_HANDLE *hHandle) = 0;

			// The handle_close(NDK_HANDLE, EventMask) will be called if return -1. 
			//virtual apr_status_t HandleException(F_HANDLE *hHandle) = 0;

			// The handle_close(const void *, EventMask) will be called if return -1.
			//virtual apr_status_t HandleTimeOut (apr_time_t ddwCurrTime, const void *arg) = 0;

			//
			virtual apr_status_t HandleClose(F_HANDLE *hHandle, EventMask dwMask) = 0;

			// Get the handle
			virtual F_HANDLE *GetHandle() 
			{
				return &m_stHandle;
			};

			// Set the I/O handle
			virtual void SetHandle (F_HANDLE *hHandle)
			{
				m_stHandle = *hHandle;
			};

			// Get the event demultiplexors.
			virtual void SetReactor(IReactor *r)
			{
				this->m_poReactor = r;
			};

			// Set the event demultiplexors.
			virtual IReactor *GetReactor(void) const
			{
				return this->m_poReactor;
			};

            virtual ~IEventHandler() {};
		protected:
			IEventHandler() {};
			IReactor                  *m_poReactor;
			F_HANDLE                   m_stHandle;

		};
    }
}


#endif